<?php
session_start();

if (!session_is_registered(myusername))
{
        header("Location: index.php");
}

?>

<?php
//  Do a Sh-Pull on the directory number and grab the sequence number
//  Increase the sequence number by 1 and use that new sequence number in the Update

?>
<form id="metaQueryForm" action="#" method="GET">
Phone Number: <input type="text" id="metaQueryString" maxlength="15"/>
<input type="button" id="metaQuerySubmit" value="query"/>
<input type="checkbox" id="queryDebug"/>
</form>
<br/>
<div id="queryResults">
Display Current sub configuration below
</div>
<script type="text/javascript">

                $('metaQueryForm').addEvent('submit', function(e){
                        if($('metaQueryString').value != ""){
                                var url = 'metaswitch/meta_query.php?';
                                url=url+'queryString='+$('metaQueryString').value;
                                if ($('queryDebug').checked) {
                                        url=url+'&debug=True';
                                }
                                else {
                                        url=url+'&debug=False';
                                }
                                url=url+'&cmd=meta_update_sub';
                                url=url+'&nocache='+Math.random();
                                /*MochaUI.updateContent({
                                        'element': $('panel1'),
                                        'loadMethod': 'xhr',
                                        'url': url,
                                        'title': 'Meta Query Results',
                                        'padding': { top: 8, right: 8, bottom: 8, left: 8 }
                                });*/
				var myRequest = new Request({
						method: 'get',
						url: url,
						onSuccess: function(response){
							$('queryResults').innerHTML = response;
							}
					});
				myRequest.send();
                        }
                });

		
		/*var request = new Request({
                	'url': 'metaswitch/meta_query.php?queryString='+$('metaQueryString').value+'&cmd=meta_update_sub&nocache='+Math.random(),
                	'method': 'get',
                	'update': 'refresh_me',
                	onComplete: function(response) {
                        	$('queryResults').set('html',response);
                	}
	        });
        
	        var query = function(){
	                request.send();
	        };
		*/

                $('metaQuerySubmit').addEvent('click', function(e){
                        if($('metaQueryString').value != ""){
                                var url = 'metaswitch/meta_query.php?';
                                url=url+'queryString='+$('metaQueryString').value;
                                if ($('queryDebug').checked) {
                                        url=url+'&debug=True';
                                }
                                else {
                                        url=url+'&debug=False';
                                }
                                url=url+'&cmd=meta_update_sub';
                                url=url+'&nocache='+Math.random();
                                /*MochaUI.updateContent({
                                        'element': $('panel1'),
                                        'loadMethod': 'xhr',
                                        'url': url,
                                        'title': 'Meta Query Results',
                                        'padding': { top: 8, right: 8, bottom: 8, left: 8 }
                                });*/
				var myRequest = new Request({
						method: 'get',
						url: url,
						onSuccess: function(response){
							$('queryResults').innerHTML = response;
							}
					});
				myRequest.send();
                                showSpinner();
                        }
                });
</script>
